package com.riguz.forks.framework.plugin;

import java.util.LinkedList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class PluginLoader {
    private static final Logger logger = LoggerFactory.getLogger(PluginLoader.class);

    protected List<Plugin> plugins = new LinkedList<Plugin>();

    public abstract void registerPlugins();

    public void registerPlugin(Plugin plugin) {
        this.plugins.add(plugin);
    }

    public void startPlugins() {
        for (Plugin plugin : plugins) {
            logger.info("starting plugin:{}", plugin.getPluginInfo());
            plugin.init();
        }
    }

    public void stopPlugins() {
        for (Plugin plugin : plugins) {
            logger.info("stopping plugin:{}", plugin.getPluginInfo());
            plugin.destroy();
        }
    }
}
